/*
 *
 * @Author: Jevon
 * @Date: 2021-09-07 14:46:32
 */

import VuiElement from '../base/element';

export default class VuiIframe extends VuiElement {
  constructor(id, classname, onload, src) {
    super();

    this._config = {
      id,
      classname,
      onload,
      src
    };
  }

  init() {
    const config = this._config;
    const container = document.createElement('iframe');
    container.className = config.classname;
    container.id = config.id;
    container.onload = config.onload;
    if (config.src) {
      container.src = config.src;
    }

    this.container = container;
    return this;
  }

  focus() {
    this.container.focus();
  }

  postMessage(data) {
    this.container.contentWindow.postMessage(data, '*');
  }

  setSrc(src) {
    this.container.src = src;
  }
}
